package service;

import java.util.ArrayList;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import entity.Admin;
import entity.Subject;
import mapper.SubjectMapper;

@Service
public class SubjectService {

	@Autowired
	private SubjectMapper subjectMapper;
	public ArrayList<Subject> findAll(){
		return subjectMapper.findAll();
	}
	public String add(Subject subject,HttpSession session) {
		Admin admin = (Admin)session.getAttribute("admin");
		if(admin==null) {
			return "没有权限";
		}else {
			subjectMapper.add(subject);
			return "添加成功";
		}
	}
	public Subject findById(String id) {
		return subjectMapper.findById(id);
	}
	public String alter(Subject subject,HttpSession session) {
		Admin admin = (Admin)session.getAttribute("admin");
		if(admin==null) {
			return "没有权限";
		}else {
			subjectMapper.alter(subject);
			return "修改成功";
		}
	}
	public String delete(Subject subject,HttpSession session) {
		Admin admin = (Admin)session.getAttribute("admin");
		if(admin==null) {
			return "没有权限";
		}else {
			subjectMapper.delete(subject.getId());
			return "删除成功";
		}
	}
}
